package com.baidu.service.impl;

import com.baidu.pojo.TbShopAudit;
import com.baidu.utils.ResultResponse;
import com.baidu.vo.SellerManageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.service.TbShopAuditService;
import com.baidu.mapper.TbShopAuditMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 *
 */
@Service
public class TbShopAuditServiceImpl extends ServiceImpl<TbShopAuditMapper, TbShopAudit>
implements TbShopAuditService{

    @Autowired
    private TbShopAuditMapper tbShopAuditMapper;

    @Override
    public ResultResponse findList(Integer page, Integer size, String name,String name2){
        if(StringUtils.isEmpty(name)){
            name="";
        }
        if(StringUtils.isEmpty(name2)){
            name2="";
        }
        Page<TbShopAudit> objectPage = new Page<>(page,size);
        Page<TbShopAudit> list = this.tbShopAuditMapper.findList(objectPage,name,name2);
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse findById(Integer id) {
        TbShopAudit tbShopAudit = this.tbShopAuditMapper.selectById(id);
        return ResultResponse.SUCCESS(tbShopAudit);
    }

    @Override
    public ResultResponse auditPass(Integer id) {
        this.tbShopAuditMapper.auditPass(id);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse auditRefuse(Integer id) {
        this.tbShopAuditMapper.auditRefuse(id);
        return ResultResponse.SUCCESS();
    }

    ////////////////////////////////////////////////////////////////////

    @Override
    public ResultResponse pageListBy(SellerManageVo vo) {
        Page<TbShopAudit> page = new Page<>(vo.getCurrent(), vo.getSize());
        if (vo.getState() != null){
            if (vo.getState() == -1){
                vo.setState(null);
            }
        }

        IPage<TbShopAudit> list = tbShopAuditMapper.pageListBy(page,vo.getCompanyName(),vo.getShopName(),vo.getState());
//        IPage<TbShopAudit> list = tbShopAuditMapper.pageListBy(page,vo);
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse getListById(Integer id) {
        TbShopAudit one = tbShopAuditMapper.selectOne(new QueryWrapper<TbShopAudit>().lambda().eq(TbShopAudit::getId, id).last("limit 1"));
        return ResultResponse.SUCCESS(one);
    }

    @Override
    public ResultResponse changeStatus(Integer id, Integer code) {
        TbShopAudit one = tbShopAuditMapper.selectOne(new QueryWrapper<TbShopAudit>().lambda().eq(TbShopAudit::getId, id).last("limit 1"));
        one.setStatus(code);
        tbShopAuditMapper.updateById(one);
        return ResultResponse.SUCCESS(one);
    }

    /////////////////////////////////////////////////////////////////////
}




